﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Demo.Model.Utils
{
    public static class DataManager
    {
        static string hobbies = "Basketball,Piano,Drums,Juggling,Programming,Snowboard,Soccer,Guitar";
        static string countries = "Argentina,Uruguay,Brasil,Bolivia,Peru,Ecuador,Chile,Colombia,Venezuela";

        public static void FillDemoData()
        {
            // Hobbies
            string[] arrHobbies = hobbies.Split(',');
            foreach (string hobbyDesc in arrHobbies)
            {
                Demo.Model.Hobby hobby = new Demo.Model.Hobby();
                hobby.Description = hobbyDesc;
                hobby.Save();
            }

            // Countries        
            string[] arrCountries = countries.Split(',');
            foreach (string countryDesc in arrCountries)
            {
                Demo.Model.Country country = new Demo.Model.Country();
                country.Description = countryDesc;
                country.Save();
            }

            // States          
            Demo.Model.State state1 = new Demo.Model.State();
            state1.Description = "State 1";
            state1.Save();

            Demo.Model.State state2 = new Demo.Model.State();
            state2.Description = "State 2";
            state2.Save();

            // Cities State 1        
            for (int i = 1; i < 10; i++)
            {
                Demo.Model.City newCity = new Demo.Model.City();
                newCity.Description = "State 1. City " + i.ToString();
                newCity.State = state1;
                newCity.Save();
            }

            // Cities State 2       
            for (int i = 1; i < 10; i++)
            {
                Demo.Model.City newCity = new Demo.Model.City();
                newCity.Description = "State 2. City " + i.ToString();
                newCity.State = state2;
                newCity.Save();
            }

            // Customer Types          
            for (int i = 1; i < 5; i++)
            {
                Demo.Model.CustomerType customerType = new Demo.Model.CustomerType();
                customerType.Description = "Type " + i.ToString();
                customerType.Save();
            }

            // Customers
            for (int i = 0; i < 50; i++)
            {
                // Address
                Demo.Model.Address address = new Demo.Model.Address();
                address.City = Demo.Model.City.FindOne();
                address.Street = "Siempre Viva";
                address.Number = "1111";

                Demo.Model.Customer customer = new Demo.Model.Customer();
                customer.LastName = "LastName" + i.ToString();
                customer.FirstName = "FirstName " + i.ToString();
                customer.Email = "e@mail.com";
                customer.Limit = 10;
                customer.Nationality = Demo.Model.Country.FindOne();
                customer.BirthDate = new DateTime(1978, 5, 5);
                customer.Address = address;
                customer.Type = Demo.Model.CustomerType.FindOne();

                // Basket
                if (i == 2)
                    customer.Hobbies.Add(Hobby.FindAllByProperty("Description", arrHobbies[0])[0]);

                // Piano            
                if (i == 7)
                    customer.Hobbies.Add(Hobby.FindAllByProperty("Description", arrHobbies[1])[0]);

                // Phones
                CustomerPhone phone = new CustomerPhone();
                phone.Type = "H";
                phone.Number = i.ToString() + "00000";
                customer.Phones.Add(phone);

                customer.Save();
            }
        }

        public static void FillTestData()
        {
            // Relleno la base con datos
            Demo.Model.Country argentina = new Demo.Model.Country();
            argentina.Description = "Argentina";
            argentina.Save();

            Demo.Model.State newState = new Demo.Model.State();
            newState.Description = "Buenos Aires";
            newState.Save();

            Demo.Model.City newCity = new Demo.Model.City();
            newCity.Description = "Lomas de Zamora";
            newCity.State = newState;
            newCity.Save();

            Demo.Model.Address address = new Demo.Model.Address();
            address.City = newCity;
            address.Street = "Siempre Viva";
            address.Number = "1111";
            address.Save();

            Demo.Model.CustomerType customerType = new Demo.Model.CustomerType();
            customerType.Description = "Paciente";
            customerType.Save();

            Demo.Model.Customer customer;

            Hobby drumsHobby = new Hobby();
            drumsHobby.Description = "Drums";

            Hobby basketballHobby = new Hobby();
            basketballHobby.Description = "Basketball";

            for (int i = 0; i < 10; i++)
            {
                customer = new Demo.Model.Customer();
                customer.LastName = "Nara " + i.ToString();
                customer.FirstName = "Sapo " + i.ToString();
                customer.Email = "sapo@sapo.com";
                customer.Limit = i;
                customer.Nationality = argentina;
                customer.BirthDate = DateTime.Now;
                customer.Address = address;

                if (i == 2)
                    customer.Hobbies.Add(drumsHobby);

                if (i == 7)
                    customer.Hobbies.Add(basketballHobby);

                // Phones
                CustomerPhone phone = new CustomerPhone();
                phone.Type = "Mobile";
                phone.Number = i.ToString() + "00000";

                customer.Save();
            }
        }
    }
}
